<template>
  <!--工作台卡片列表组件-->
  <div class="card_box">
    <div class="empty_list" v-if="cardList.length === 0">
      <div class="empty_panel">
        <img src="@/assets/img/pic_worker_empty.png">
        <span>暂无数据</span>
      </div>
    </div>
    <div
      v-if="cardList.length > 0"
      class="bench_board_card"
      :class="cardStyle(workstage)"
      v-for="(workstage, index) in cardList"
      @click="clickCard(workstage)"
      :key="index">
      <div class="card_header">
        <div class="card_header_left">
          <p class="order_item" :class="cardStyle(workstage)">{{workstage.sort}}</p>
          <p class="workstage_name">{{workstage.workstageName}}</p>
        </div>
        <el-checkbox v-model="workstage.checked" @change="changeCard" @click.stop.native></el-checkbox>
      </div>
      <div class="card_content">
        <p class="copy_row"><span>周转码</span>：{{workstage.turnoverNumber}}
          <span class="copy_btn" @click.stop="copyCard(workstage.turnoverNumber, $event)">复制</span>
        </p>
        <p class="copy_row"><span>物料名称</span>：{{workstage.materialName}}
          <span class="copy_btn" @click.stop="copyCard(workstage.materialName, $event)">复制</span>
        </p>
        <p class="copy_row"><span>物料编码</span>：{{workstage.materialNumber}}
          <span class="copy_btn" @click.stop="copyCard(workstage.materialNumber, $event)">复制</span>
        </p>
        <p><span>计划数量</span>：{{workstage.productionQuantity}}</p>
        <p><span>投料数量</span>：{{workstage.inputQuantity}}</p>
        <p><span>计划时间</span>：{{formatDate(workstage.planStartDate) + ' 至 ' + formatDate(workstage.planEndDate)}}</p>
        <p><span>上料状态</span>：{{workstage.materialStatusLabel}}</p>
        <p><span>参数记录</span>：{{workstage.parameterRecordId ? '已记录' : '未记录'}}</p>
      </div>
      <div class="card_footer">
        <div class="dict_block">
          <mes-cell-comp
            v-for="(item, index) in columns"
            :key="index"
            :column="item"
            :colConfig="item.colConfig"
            :row="workstage"
          ></mes-cell-comp>
        </div>
        <span v-if="workstage.completeQuantity" class="complete_number">完工数量: {{workstage.completeQuantity}}</span>
      </div>
    </div>
    <div class="empty_card" v-for="(card, index) in emptyCardList" :key="index + 'empty'">{{card}}</div>
  </div>
</template>

<script>
import clip from '@/utils/clipboard'
export default {
  name: 'BenchBoardCard',
  data() {
    return {
      columns: [],
      cardList: []
    }
  },
  computed: {
    emptyCardList() {
      const num = this.cardList.length % 4
      if (num > 0) {
        const length = 4 - num
        return new Array(length).fill('')
      }
    }
  },
  mounted() {
    this.columns = [
      { colConfig: {comp: 'WorkStageProcessStatus'} },
      { colConfig: {comp: 'TurnoverStatus'} },
    ]
  },
  methods: {
    reload(list) {
      this.cardList = JSON.parse(JSON.stringify(list))
    },
    // 卡片样式
    cardStyle(workstage) {
      const status = workstage.workstageProcessStatusValue
      switch (status) {
        case 'ToBeStarted':
          return 'to_be_started'
        case 'Started':
          return 'started'
        case 'NotArrive':
          return 'not-arrive'
        case 'Finished':
          return 'finished'
      }
    },
    // 格式化日期
    formatDate(date) {
      if (date) {
        return this.moment(date).format('YYYY-MM-DD')
      }
    },
    // 选择框change
    changeCard() {
      this.$emit('changeCard', this.cardList)
    },
    // 点击卡片
    clickCard(workstage) {
      this.$emit('clickCard', workstage)
    },
    // 复制卡片
    copyCard(value, event) {
      clip(value, event)
      this.tipMessage('success', '复制成功')
    },
    /**
     * 提示
     * @param type 提示类型
     * @param str 提示内容
     * @param duration 提示时间
     */
    tipMessage(type, str, duration) {
      this.$message({
        type: type,
        message: str,
        duration: duration || 1500,
        center: true
      })
    }
  }
}
</script>

<style lang="less">
  .card_box{
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
  }
  .empty_list{
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    .empty_panel{
      text-align: center;
      margin-left: -60px;
      margin-top: 200px;
      img{
        width: 120px;
        height: 120px;
        display: block;
      }
      span{
        color: #a1b1c1;
      }
    }
  }
  .bench_board_card{
    width: 370px;
    background-color: #fff;
    border: solid 1px #dcdfe6;
    min-height: 320px;
    background-repeat: no-repeat;
    background-size: contain;
    background-position: 12px 0;
    cursor: pointer;
    position: relative;
    font-size: 14px;
    color: #333;
    margin-bottom: 30px;
    .card_header{
      position: absolute;
      left: -1px;
      width: 100%;
      height: 50px;
      padding: 15px 0 0 0;
      box-sizing: border-box;
      background-repeat: no-repeat;
      background-size: 300px 35px;
      background-position-y: 15px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding-left: 4px;
      .card_header_left{
        display: flex;
        align-items: center;
        height: 35px;
        .order_item{
          width: 24px;
          height: 24px;
          border-radius: 50%;
          background-color: #fff;
          text-align: center;
          line-height: 24px;
          font-size: 14px;
          font-weight: 600;
          &.not-arrive{
            color:#ff6868;
          }
          &.to_be_started{
            color:#2196f3;
          }
          &.started{
            color:#ffab00;
          }
          &.finished{
            color:#45c263;
          }
        }
        .workstage_name{
          font-size: 16px;
          color:#fff;
          padding-left: 10px;
        }
      }
      .el-checkbox{
        width: 80px;
        height: 40px;
        position: relative;
        .el-checkbox__input{
          position: absolute;
          right: 15px;
          top: 50%;
          margin-top: -8px;
        }
      }
    }
    .card_content{
      padding-top: 65px;
      padding-left: 30px;
      margin-bottom: 15px;
      p{
        margin-bottom: 5px;
        word-break: break-all;
        span{
          display: inline-block;
          width: 58px;
          text-align-last: justify;
        }
        .copy_btn{
          width: 24px;
          text-align: center;
          color: #0066cc;
          border-radius: 1px;
          padding: 0 2px;
          cursor: pointer;
          font-size: 12px;
          display: none;
          margin-left: 10px;
          user-select: none !important;
          background-color: rgba(33, 150, 243, 0.15);
          &:active{
            background-color: rgba(33, 150, 243, 0.25) !important;
          }
        }
        &.copy_row:hover{
          color: #0066cc;
          .copy_btn{
            display: inline-block;
          }
        }
      }
    }
    .card_footer{
      height: 50px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-top: solid 1px #ebeef7;
      padding-left: 30px;
      .dict_block{
        display: flex;
        align-items: center;
        div{
          margin-right: 10px;
        }
      }
      .complete_number{
        padding-right: 14px;
      }
    }
    &:hover{
      box-shadow: 0px 2px 5px 0px rgba(126, 142, 159, 0.5);
    }
    &.not-arrive{
      background-image: url('../../assets/img/NotArrive_left.png');
      .card_header{
        background-image: url('../../assets/img/NotArrive_header.png');
      }
    }
    &.to_be_started{
      background-image: url('../../assets/img/ToBeStarted_left.png');
      .card_header{
        background-image: url('../../assets/img/ToBeStarted_header.png');
      }
    }
    &.started{
      background-image: url('../../assets/img/Started_left.png');
      .card_header{
        background-image: url('../../assets/img/Started_header.png');
      }
    }
    &.finished{
      background-image: url('../../assets/img/Finished_left.png');
      .card_header{
        background-image: url('../../assets/img/Finished_header.png');
      }
    }
  }
  .empty_card{
    width: 370px;
    min-height: 320px;
  }
</style>
